<template>
  <div>
    <LRheader :center="center"></LRheader>
    <div class="main">
      <van-form @submit="onSubmit" label-align="center">
        <div class="renshu van-cell">
          <span class="da">人数</span>
          <div>
            <van-field
              name="daren"
              label="大人"
              class="kuan"
              label-width="45px"
            >
              <template #input
                ><van-stepper
                  v-model="menuInfo.daren"
                  theme="round"
                  button-size="18"
                  disable-input
                />
              </template>
            </van-field>
          </div>
          <div>
            <van-field
              name="ertong"
              label="儿童"
              class="kuan"
              label-width="45px"
            >
              <template #input
                ><van-stepper
                  v-model="menuInfo.ertong"
                  theme="round"
                  button-size="18"
                  disable-input
                />
              </template>
            </van-field>
          </div>
        </div>
        <van-field
          readonly
          clickable
          name="departure"
          :value="menuInfo.departure"
          label="出发日期"
          placeholder="请选择出发日期"
          @click="showPicker = true"
        />
        <van-popup v-model="showPicker" position="bottom">
          <van-datetime-picker
            v-model="menuInfo.currentDate"
            type="date"
            title="选择年月日"
            :min-date="minDate"
            :max-date="maxDate"
            @confirm="onPicker"
            @cancel="showPicker = false"
          />
        </van-popup>

        <van-field
          readonly
          clickable
          name="region"
          :value="menuInfo.region"
          label="地区选择"
          placeholder="请选择出发城市"
          @click="showArea = true"
        />
        <van-popup v-model="showArea" position="bottom">
          <van-area
            :area-list="areaList"
            @confirm="onConfirm"
            @cancel="showArea = false"
          />
        </van-popup>

        <van-field
          v-model="menuInfo.linkman"
          name="linkman"
          label="联系人"
          placeholder="必填"
          :rules="[{ required: true, message: '必须填哦' }]"
        />
        <van-field
          v-model="menuInfo.cell"
          name="cell"
          label="手机号码"
          placeholder="手机号码"
          value="menuInfo.phone"
        />
        <van-field
          v-model="menuInfo.weixin"
          name="weixin"
          label="微信号"
          placeholder="微信号"
        />

        <van-field
          disabled
          v-model="menuInfo.arrive"
          name="arrive"
          label="目的地"
          placeholder="请问目的地是哪里"
        />
        <van-field
          disabled
          v-model="menuInfo.travel"
          name="travel"
          label="旅游天数"
          placeholder="请问具体旅游多少天"
        />
        <van-field
          v-model="menuInfo.rests"
          type="textarea"
          name="rests"
          label="其他要求"
          placeholder="请问还有别的需求"
        />
        <div style="margin: 10px 100px">
          <van-button round block type="info" native-type="submit"
            >修改定制</van-button
          >
        </div>
      </van-form>
    </div>
  </div>
</template>

<script>
import LRheader from "../../components/Nav/LRheader";
import Vue from "vue";
import url from "../../config/modules/user";
import moment from "moment";
import {
  Form,
  Button,
  Field,
  Stepper,
  DatetimePicker,
  Popup,
  Area,
  Toast,
} from "vant";
Vue.use(Toast);
Vue.use(Popup);
Vue.use(Area);
Vue.use(DatetimePicker);
Vue.use(Stepper);
Vue.use(Field);
Vue.use(Button);
Vue.use(Form);
const areaList = {
  province_list: {
    110000: "广东省",
    120000: "福建省",
  },
  city_list: {
    110100: "深圳市",
    110200: "广州市",

    120100: "厦门市",
    120200: "福州市",
  },
  county_list: {
    110101: "福田区",
    110102: "罗湖区",

    110201: "天河区",
    110202: "珠海区",

    120101: "岛",
    120102: "海",

    120201: "山",
    120202: "谷",

    // ....
  },
};
export default {
  data() {
    return {
      center: "旅游计划",
      menuInfo: {},
      showArea: false,
      areaList,
      // 日期
      showPicker: false,
      minDate: new Date(2020, 0, 1),
      maxDate: new Date(2025, 10, 1),
      currentDate: new Date(2021, 0, 17),
    };
  },
  methods: {
    // 城市
    onConfirm(values) {
      this.menuInfo.region = values
        .filter((item) => !!item)
        .map((item) => item.name)
        .join("-");
      this.showArea = false;
    },
    //日期
    onPicker(date) {
      let departure = moment(date).format("YYYY年MM月DD日");
      this.menuInfo.departure = departure;
      this.showPicker = false;
    },

    onSubmit(values) {
      console.log(values);
      // this.$http.post(url.order,values).then((ret)=>{
      //   console.log(ret)
      // })
      this.$http.post(url.genxin, values).then((res) => {
        if (res.err === 0) {
          Toast.success(res.msg);
        } else {
           Toast.fail(res.msg);
        }
      });
    },
  },

  created() {
    // 进入该组件隐藏底部导航
    this.$store.commit("my/setIsShow", false);
    this.$http.get(url.userorder).then((ret) => {
      this.menuInfo = ret.data;
    });
  },
  //   组件注册
  components: {
    LRheader,
  },
};
</script>

<style scoped>
.main {
  margin-top: 40px;
}
.da {
  display: block;
  margin: 0 10px;
  float: left;
}
.kuan {
  margin-left: 10px;
  width: 130px;
  padding: 0 !important;
  float: left;
}
.van-field__label {
  margin-right: 0;
}
</style>